package com.youfang.sixthmedia.ui.detail;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.gzit.utils.AndroidUtils;
import com.gzit.utils.StringUtils;
import com.youfang.sixthmedia.R;
import com.youfang.sixthmedia.common.YoufangContext;
import com.youfang.sixthmedia.message.model.DetailBuilding;

public class DetailConsultantActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.detail_consultant_activity);

		DetailBuilding detail = YoufangContext.getCurrentBuilding();
		if (detail == null) {
			return;
		}

		this.updateUI(detail);

	}

	private void updateUI(final DetailBuilding detail) {

		TextView isVerify = (TextView) this.findViewById(R.id.isverify);
		isVerify.setText("1".equals(detail.isverify) ? "已验证" : "未验证");

		TextView buildingname_title = (TextView) this
				.findViewById(R.id.buildingname_title);
		buildingname_title.setText(detail.buildingname);

		TextView Consultantname = (TextView) this
				.findViewById(R.id.Consultantname);
		Consultantname
				.setText(StringUtils.isBlank(detail.Consultantname) ? detail.buildingname
						: detail.Consultantname);

		TextView Consultantphone = (TextView) this
				.findViewById(R.id.Consultantphone);
		Consultantphone.setText(detail.Consultantphone);

		TextView Consultantemail = (TextView) this
				.findViewById(R.id.Consultantemail);
		Consultantemail.setText(detail.Consultantemail);

		TextView introduce = (TextView) this.findViewById(R.id.introduce);
		introduce.setText(detail.introduce);

		// 马上联络事件
		this.findViewById(R.id.contactBtn).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						if (StringUtils.isBlank(detail.Consultantphone)) {
							AndroidUtils.toastShort("抱歉，顾问没有留下电话，不能拨打");
							return;

						}

						Intent intent = new Intent(Intent.ACTION_CALL, Uri
								.parse("tel:" + detail.Consultantphone));
						startActivity(intent);

					}
				});

	}
}
